﻿#include <iostream>
#include <memory>

class Person {
public:
    Person(const std::string& name) : name(name) {
        std::cout << name << " create\n";
    }
    ~Person() {
        std::cout << name << " xiaohui\n";
    }
private:
    std::string name;
};

int main() {
    std::shared_ptr<Person> p1 = std::make_shared<Person>("Alice");
    {
        std::shared_ptr<Person> p2 = p1; // 引用计数 +1
        std::cout << "yinyong_count: " << p1.use_count() << "\n";
    } // p2 离开作用域，引用计数 -1
    std::cout << "yinyong_count: " << p1.use_count() << "\n";
    return 0;
}
